package com.zx._03_并发.chapter_01_atomic;

import java.util.concurrent.atomic.AtomicStampedReference;
import lombok.extern.slf4j.Slf4j;

/**
 * 线程安全——AtomicStampedReference
 */
@Slf4j
public class Demo_07 {

    private static AtomicStampedReference<Integer> count = new AtomicStampedReference<Integer>(0, 0);

    public static void main(String[] args) {
        count.compareAndSet(0, 2, 0, 2);//期望数值为0，并且戳是0的时候，去修改数值和戳，只要有一个不同就不能修改
        count.compareAndSet(0, 3, 0, 3);
        log.info("stamp={}, reference ={}", count.getStamp(), count.getReference());
    }
}
